package com.company.app.boImpl;

import java.util.List;

import com.company.app.bo.ProductTypeBO;
import com.company.app.dao.ProductTypeDAO;
import com.company.app.entities.ProductType;

/**
 * The Class ProducTypeBOImpl.
 */
public class ProductTypeBOImpl implements ProductTypeBO {
	
	/** The product type dao. */
	private ProductTypeDAO productTypeDAO;


	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#getProductById(java.lang.Long)
	 */
	@Override
	public ProductType getProductById(Long id) {
		return this.productTypeDAO.getEntityById(id);
	}


	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#searchProductTypeByFilter(com.company.app.entities.ProductType)
	 */
	@Override
	public List<ProductType> searchProductTypes(List<ProductType> productType) {
		return this.productTypeDAO.searchEntities(productType);
	}


	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#executeProductTypeBussinessLogic()
	 */
	@Override
	public boolean executeProductTypeBussinessLogic() {
		return false;
	}


	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#createProductType(com.company.app.entities.ProductType)
	 */
	@Override
	public ProductType createProductType(ProductType productType) {
		return this.productTypeDAO.createEntity(productType);
	}

	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#updateProductType(com.company.app.entities.ProductType)
	 */
	@Override
	public boolean updateProductType(ProductType productType) {
		return this.productTypeDAO.updateEntity(this.buildProductType(productType))!=null;
	}
	
	/**
	 * Builds the product type.
	 *
	 * @param param the param
	 * @return the product type
	 */
	private ProductType buildProductType(ProductType param){
		ProductType productyTpeEntity = this.getProductById(param.getId());
		if (productyTpeEntity!=null){
			if (param.getName()!=null){
				productyTpeEntity.setName(param.getName());
			}
			if (param.getDescription()!=null){
				productyTpeEntity.setDescription(param.getDescription());
			}
		}
		return productyTpeEntity;
	}
	
	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#deleteProductType(com.company.app.entities.ProductType)
	 */
	@Override
	public boolean deleteProductType(ProductType productType) {
		this.productTypeDAO.deleteEntity(productType);
		return true;
	}
	
	/* (non-Javadoc)
	 * @see com.company.app.bo.ProductTypeBO#getAllProductType()
	 */
	@Override
	public List<ProductType> getAllProductType() {
		return this.productTypeDAO.getAllEntity();
	}
	
	/**
	 * Sets the product type dao.
	 *
	 * @param productTypeDAO the new product type dao
	 */
	public void setProductTypeDAO(ProductTypeDAO productTypeDAO) {
		this.productTypeDAO = productTypeDAO;
	}


	

}
